package com.tiny.mirror.service.product.interfaces.controller;

import com.api.tiny.mirror.service.product.PlatformApiService;
import com.api.tiny.mirror.service.product.request.CreatePlatformRequest;
import com.api.tiny.mirror.service.product.request.PagePlatformRequest;
import com.api.tiny.mirror.service.product.request.UpdatePlatformAbilityRequest;
import com.api.tiny.mirror.service.product.request.UpdatePlatformRequest;
import com.api.tiny.mirror.service.product.response.PlatformAbilityVO;
import com.api.tiny.mirror.service.product.response.PlatformVO;
import com.tiny.mirror.basic.log.annotation.LogBody;
import com.tiny.mirror.basic.web.dto.response.BasePageResponse;
import com.tiny.mirror.basic.web.dto.response.BaseResponse;
import com.tiny.mirror.service.product.application.command.PlatformCmdService;
import com.tiny.mirror.service.product.application.query.PlatformQryService;
import java.util.Arrays;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/9/25
 */
@RestController
public class PlatformController implements PlatformApiService {

  @Resource
  private PlatformQryService platformQryService;
  @Resource
  private PlatformCmdService platformCmdService;

  @LogBody
  @Override
  public BasePageResponse<PlatformVO> page(@RequestBody @Validated PagePlatformRequest request) {
    return platformQryService.page(request);
  }

  @Override
  public BaseResponse<PlatformVO> getInfo(@PathVariable(value = "id") Long id) {
    return BaseResponse.success(platformQryService.getInfo(id));
  }

  @LogBody
  @Override
  public BaseResponse<Long> create(@RequestBody @Validated CreatePlatformRequest request) {
    return BaseResponse.success(platformCmdService.create(request));
  }

  @LogBody
  @Override
  public BaseResponse<Void> update(@RequestBody @Validated UpdatePlatformRequest request) {
    platformCmdService.update(request);
    return BaseResponse.success();
  }

  @Override
  public BaseResponse<Integer> delete(@PathVariable(value = "ids") Long[] ids) {
    return BaseResponse.success(platformCmdService.delete(Arrays.asList(ids)));
  }

  @Override
  public BaseResponse<PlatformAbilityVO> getAuthAbility(@PathVariable("id") Long id) {
    return BaseResponse.success(platformQryService.getAuthAbility(id));
  }

  @Override
  public BaseResponse<Void> updateAuthAbility(
      @RequestBody @Validated UpdatePlatformAbilityRequest request
  ) {
    platformCmdService.updateAuthAbility(request);
    return BaseResponse.success();
  }
}
